home *** CD-ROM | disk | FTP | other *** search
/ bioinformatics.org / bioinformatics.org_software.tar / www.bioinformatics.org / download / ecell2 / ecell220setup.exe / {app} / standard / SRCJ / Engine.java < prev    next >
Text File  |  2002-05-17  |  22KB  |  937 lines

  1. /**
  2.  * title:     Engine class (Engine.java)<p>
  3.  * description  : Controller Panel class <p>
  4.  * Copyright (C) 1996-2001 Keio University <p>
  5.  * Copyright (C) 1998-2001 Japan Science and Technology Corporation (JST)<p>
  6.  *               GNU General Public Licence <p>
  7.  * Division:     Mitui Knowledge Industry Co. Ltd. Bioscience division <p>
  8.  * Version :     $Id: Engine.java,v 1.6 2002/05/13 00:23:04 ota Exp $ <p>
  9.  */
  10.  
  11.  
  12. package ecell;
  13.  
  14. import java.lang.*;
  15. import java.io.*;
  16. import java.util.*;
  17.  
  18.  
  19. class Engine
  20. {
  21.     
  22.     private int e_update_interval = 100;
  23.     
  24.     private int e_flags = 0;
  25.     
  26.     private int e_update_counter = 0;
  27.     
  28.     private boolean e_ready = false;
  29.     
  30.     private boolean e_running = false;
  31.     
  32.     private double e_time_to_stop = -1.0;
  33.     
  34.     private String e_cell_state_name = "";
  35.     
  36.     private String e_script_name = "";
  37.     
  38.     private String e_rule_name = "";
  39.     
  40.     private boolean e_debug = false;
  41.     
  42.     // 2002.3.19 akira shiozawa
  43.     private boolean bScriptRunning = false;
  44.     
  45.     private MainWindow window = null;
  46.     
  47.     public static final String DEFAULT_ECS_NAME = "default.ecs";
  48.  
  49.     public static final int CP_ENABLE_START = 0x0001;
  50.     public static final int CP_ENABLE_STOP = 0x0002;
  51.     public static final int CP_ENABLE_STEP = 0x0004;
  52.     public static final int CP_ENABLE_PREFERENCE = 0x0008;
  53.     public static final int CP_ENABLE_LOAD_RULE = 0x0010;
  54.     public static final int CP_ENABLE_LOAD_SCRIPT = 0x0020;
  55.     public static final int CP_ENABLE_LOAD_CS = 0x0040;
  56.     public static final int CP_ENABLE_SAVE_CS = 0x0080;
  57.     public static final int CP_ENABLE_QUIT = 0x0100;
  58.     public static final int CP_ENABLE_TRACER = 0x0200;
  59.     public static final int CP_ENABLE_SUBSTANCE = 0x0400;
  60.     public static final int CP_ENABLE_REACTOR = 0x0800;
  61.     
  62.     public static String msg_welcome = "";
  63. /**
  64.         "E-CELL 2 (C) 1998-2001 Keio university and JST\n" +
  65.         "Version 2.12 $Date: 2002/05/13 00:23:04 $\n" +
  66.         "This is free software without any warranty under GPL.\n" +
  67.         "Please see http://bioinformatics.org/ for detail.\n";
  68. **/
  69.  
  70.     public static String msg_help = "";
  71.  
  72.     // 2002.4 akira shiozawa
  73.     private ScriptInterpreter script = null;
  74.  
  75.  
  76.  
  77.     /**
  78.      * constructor
  79.      * @param window MainWindow
  80.      */
  81.     public Engine( MainWindow window )
  82.     {
  83.         setMainWindow( window );
  84.         
  85.         createMessages();
  86.         //cp_new();
  87.     }
  88.  
  89.  
  90.     public void startBatch()
  91.     {
  92.         e_flags &= ~(Engine.CP_ENABLE_START | Engine.CP_ENABLE_STEP);
  93.         e_flags |= Engine.CP_ENABLE_STOP;
  94.         //cp_enable(e_flags);
  95.         
  96.         e_running = true;
  97.         while( e_running )
  98.         {
  99.             update( this.e_update_interval );
  100.             updateInterface();
  101.         }
  102.         
  103.         e_flags |= (Engine.CP_ENABLE_START | Engine.CP_ENABLE_STEP);
  104.         e_flags &= ~Engine.CP_ENABLE_STOP;
  105.         //cp_enable( e_flags );
  106.     }
  107.  
  108.     /**
  109.      * start simulation
  110.      * @return int
  111.      */
  112.     public int start()
  113.     {
  114.         getMainWindow().messageWindow.setDebugMessage( "-----> start@" + getClass().getName() + "()" );
  115.         int ret = 1;
  116.         
  117.         e_flags &= ~(Engine.CP_ENABLE_START | Engine.CP_ENABLE_STEP);
  118.         e_flags |= Engine.CP_ENABLE_STOP;
  119.         //cp_enable( e_flags );
  120.         e_running = true;
  121.         
  122.         update( e_update_interval );
  123.         updateInterface();
  124.  
  125.         if ( !e_running )
  126.         {
  127.             e_flags |= (Engine.CP_ENABLE_START | Engine.CP_ENABLE_STEP);
  128.             e_flags &= ~Engine.CP_ENABLE_STOP;
  129.             //getMinWindow().df.cp_enable( e_flags );
  130.             ret = 0;
  131.         }
  132.         
  133.         getMainWindow().messageWindow.setDebugMessage( "<----- start@" + getClass().getName() + "( ret:" + ret + " )" );
  134.         return ret;
  135.     }
  136.     
  137.     
  138.     /**
  139.      * do the simulation in 1 step cycle
  140.      * @return int
  141.      */
  142.     public int step()
  143.     {
  144.         return update( 1 );
  145.     }
  146.     
  147.     /**
  148.      * calculate the system in specified steps
  149.      * @param steps int
  150.      * @return int
  151.      */
  152.     public int update( int steps )
  153.     {
  154.         getMainWindow().messageWindow.setDebugMessage( "-----> update@" + getClass().getName() + "( steps:" + steps + " )" );
  155. //System.out.println( "-----> update (time_to_stop:" + e_time_to_stop + ")" );
  156.         int ret = getMainWindow().df.calc( steps, this.e_time_to_stop );
  157.  
  158.         switch( ret )
  159.         {
  160.  
  161.         case 1:        // ECS2_CALC_STEP
  162.  
  163.             break;
  164.  
  165.         case 2:        //ECS2_CALC_TIME
  166.  
  167.             //e_time_to_stop = MAX_DOUBLE;
  168.             setTimeToStop( Double.MAX_VALUE );
  169.  
  170.             stop();
  171.  
  172.             //cp_stop();
  173.             getMainWindow().df.stopThread();
  174. /**
  175.             // 2002.3.19 akira shiozawa
  176.             if( getScriptRunning() )
  177.             {
  178.                 ScriptInterpreter.load_script( this, "" );
  179.             }
  180. **/
  181.             
  182.             break;
  183.  
  184.         case 3:        //ECS2_CALC_FULL
  185.  
  186.             //dg_tmp_full();
  187.             getMainWindow().df.showMessage1( "E-CELL2 : disk full for temprary file.\n" );
  188.  
  189.             stop();
  190.  
  191.             //cp_stop();
  192.             getMainWindow().df.stopThread();
  193. /**
  194.             // 2002.3.19 akira shiozawa
  195.             if( getScriptRunning() )
  196.             {
  197.                 ScriptInterpreter.stop_script( this );
  198.             }
  199. **/
  200.             break;
  201.  
  202.         case 4:        //ECS2_CALC_ERROR
  203.  
  204.         default:
  205.  
  206.             stop();
  207.  
  208.             //cp_stop();
  209.             getMainWindow().df.stopThread();
  210. /**
  211.             // 2002.3.19 akira shiozawa
  212.             if( getScriptRunning() )
  213.             {
  214.                 ScriptInterpreter.stop_script( this );
  215.             }
  216. **/
  217.             break;
  218.  
  219.         }
  220.         getMainWindow().messageWindow.setDebugMessage( "<----- update@" + getClass().getName() + "( ret:" + ret + " )" );
  221.         return ret;
  222.     }
  223.  
  224.     /**
  225.      * update all interfaces
  226.      * @return void
  227.      */
  228.     public void updateInterface()
  229.     {
  230.         getMainWindow().messageWindow.setDebugMessage( "-----> updateInterface@" + getClass().getName() + "()" );
  231.     
  232.         getMainWindow().df.updateInterface();
  233.         
  234.         //cp_update(ecs2_get_time());
  235.         getMainWindow().messageWindow.setDebugMessage( "<----- updateInterface@" + getClass().getName() + "()" );
  236.     }
  237.  
  238.  
  239.     /**
  240.      * ready to go
  241.      * @return void
  242.      */
  243.     public void readyToGo()
  244.     {
  245.         e_flags = (CP_ENABLE_START | CP_ENABLE_STEP | CP_ENABLE_PREFERENCE |
  246.                    CP_ENABLE_LOAD_SCRIPT | CP_ENABLE_LOAD_CS | CP_ENABLE_SAVE_CS |
  247.                    CP_ENABLE_QUIT | CP_ENABLE_TRACER | CP_ENABLE_SUBSTANCE | CP_ENABLE_REACTOR);
  248.         //cp_enable(e_flags);
  249.     }
  250.     
  251.     /**
  252.      * startup the system
  253.      * @return void
  254.      */
  255.     public void startup()
  256.     {
  257.         getMainWindow().messageWindow.setDebugMessage( "-----> startup@" + getClass().getName() + "()" );
  258.  
  259.         loadDefaultScript();
  260.  
  261.         getMainWindow().messageWindow.setDebugMessage( "<----- startup@" + getClass().getName() + "()" );
  262.     }
  263.     
  264.     /**
  265.      * load specified cell state file
  266.      * @param filename String
  267.      * @return void
  268.      */
  269.     public void loadCellState( String filename )
  270.     {
  271.         getMainWindow().messageWindow.setDebugMessage( "-----> loadCellState@" + getClass().getName() + "( filename:" + filename + " )" );
  272.  
  273.         e_cell_state_name = filename;
  274.         updateFileName();
  275.         
  276.         getMainWindow().df.loadCs( this.e_cell_state_name );
  277.  
  278.         getMainWindow().messageWindow.setDebugMessage( "<----- loadCellState@" + getClass().getName() + "()" );
  279.     }
  280.     
  281.     /**
  282.      * save cell state to the specified file
  283.      * @param filename String
  284.      * @return void
  285.      */
  286.     public int saveCellState( String filename )
  287.     {
  288.         getMainWindow().messageWindow.setDebugMessage( "-----> saveCellState@" + getClass().getName() + "( filename:" + filename + " )" );
  289.  
  290.         e_cell_state_name = filename;
  291.         
  292.         int ret = getMainWindow().df.saveCs( this.e_cell_state_name );
  293.  
  294.         getMainWindow().messageWindow.setDebugMessage( "<----- saveCellState@" + getClass().getName() + "()" );
  295.         
  296.         return ret;
  297.     }
  298.     
  299.     /**
  300.      * load specified rule file
  301.      * @param filename String
  302.      * @return int
  303.      */
  304.     public boolean loadRule( String filename )
  305.     {
  306.         getMainWindow().messageWindow.setDebugMessage( "-----> loadRule@" + getClass().getName() + "( filename:" + filename + " )" );
  307.  
  308.         e_rule_name = filename;
  309.         updateFileName();
  310.         
  311.         getMainWindow().df.loadRule( filename );
  312.  
  313.         boolean ret = ready();
  314.         getMainWindow().setRuleFlag( ret );
  315.         
  316.         if( ret && e_time_to_stop < 0.0 )
  317.         {
  318.             setTimeToStop( Double.MAX_VALUE );
  319.         }
  320.         
  321.         getMainWindow().messageWindow.setDebugMessage( "<----- loadRule@" + getClass().getName() + "( ret:" + ret + " )" );
  322.         return ret;
  323.         }
  324.     
  325.     /**
  326.      * update file names
  327.      * @return void
  328.      */
  329.     public void updateFileName()
  330.     {
  331.         //cp_name(e_rule_name.c_str(), e_script_name.c_str(),  e_cell_state_name.c_str(), e_cs_time);
  332.     }
  333.     
  334.     /**
  335.      * load the specified script file
  336.      * @param filename String
  337.      * @return void
  338.      */
  339.     public void loadScript( String filename )
  340.     {
  341.         getMainWindow().messageWindow.setDebugMessage( "-----> loadScript@" + getClass().getName() + "( filename:" + filename + " )" );
  342.         this.e_script_name = filename;
  343.         this.updateFileName();
  344.         
  345.         
  346.         // 2002.4 akira shiozawa
  347.         if( !getScriptRunning() )
  348.         {
  349.             getMainWindow().df.saveScriptFileName( filename );
  350.             this.script = new ScriptInterpreter( this );
  351.             // 2002.5
  352.             getMainWindow().setScriptFileName( filename );
  353.         }
  354.         int ret = script.load_script( /*this,*/ filename );
  355.         
  356.         if( ret == 0 )
  357.         {
  358.             stopScript();
  359.             stop();
  360.         }
  361.         
  362.         //int ret = ScriptInterpreter.load_script( this, filename );
  363.  
  364.         getMainWindow().setScriptFlag( (ret == 0)? true : false, e_running );
  365.  
  366.         getMainWindow().messageWindow.setDebugMessage( "<----- loadScript@" + getClass().getName() + "()" );
  367.     }
  368.     
  369.     /**
  370.      * release shared objects and quitting the system
  371.      * @return void
  372.      */
  373.     public void quit()
  374.     {
  375.         getMainWindow().df.releaseReactor();
  376.         
  377.         //exit( 0 );
  378.     }
  379.     
  380.     /**
  381.      * load the defaut script file
  382.      * @return void
  383.      */
  384.     public void loadDefaultScript()
  385.     {
  386.         getMainWindow().messageWindow.setDebugMessage( "-----> loadDefaultScript@" + getClass().getName() + "()" );
  387.         String filename = 
  388.             (e_script_name.equals( "" ))? Engine.DEFAULT_ECS_NAME : this.e_script_name;
  389.  
  390.         File fl = new File( filename );
  391.         if( fl.isFile() )
  392.         {
  393.             //*theMessageWindow << "Script file [" << filename <<
  394.             //"] found. executing the script..\n";
  395.             loadScript( filename );
  396.         }
  397.         else
  398.         {
  399.             //*theMessageWindow << "Script file ["<< filename <<
  400.             //"] not found or cannot read it.\n";
  401.         }
  402.         getMainWindow().messageWindow.setDebugMessage( "<----- loadDefaultScript@" + getClass().getName() + "()" );
  403.     }
  404.  
  405.  
  406.     /**
  407.      * create the help message strings
  408.      * @return void
  409.      */
  410.     private void createMessages()
  411.     {
  412.         StringBuffer buf = new StringBuffer();
  413.         
  414.         // create help message string
  415.         buf.append( "Options :\n" );
  416.         buf.append( "  -a \t\tset user default accumulator.\n" );
  417.         buf.append( "  -c \t\tload save time of .cs file as well. (start up time only)\n" );
  418.         buf.append( "  -d \t\tdebug mode.\n" );
  419.         buf.append( "  -f FILE\t\trun a E-CELL Script(.ecs) file\n" );
  420.         
  421. //#ifdef    NOT_IMPLEMENTED
  422. //#ifdef    _Windows
  423.         if( System.getProperty( "os.name" ).toLowerCase().indexOf( "windows" ) > 0 )
  424.         {
  425.             buf.append( "  -r PATH\t\tsemicolon-separated search path to reactors\n" );
  426.         }
  427. //#else
  428.         else
  429.         {
  430.             buf.append( "  -r PATH\t\tcolon-separated search path to reactors\n" );
  431.         }
  432. //#endif    /* _Windows */
  433. //#endif    /* NOT_IMPLEMENTED */
  434.         buf.append( "  -t PATH\t\ttemporary file directory\n" );
  435.         buf.append( "  -u INTEGER\t\tset default update depth.\n" );
  436.         buf.append( "  -h     \t\tprint this message\n" );
  437.         
  438.         Engine.msg_help = buf.toString();
  439.         
  440.         // 2002.1.24 create welcome message string
  441.         buf = new StringBuffer();
  442.         buf.append( "E-CELL 2 (C) 1998-2002 Keio university and JST\n" );
  443.         buf.append( "Version " );
  444.         buf.append( window.df.getCoreVersion() );
  445.         buf.append( "\n" );
  446.         buf.append( "This is free software without any warranty under GPL.\n" );
  447.         buf.append( "Please see http://bioinformatics.org/project/?group_id=49 for detail.\n" );
  448.         
  449.         Engine.msg_welcome = buf.toString();
  450.     }
  451.     
  452.     /**
  453.      * stop running
  454.      * @return void
  455.      */
  456.     public void stop()
  457.     {
  458.         this.setRunningStatus( false );
  459.         //getMainWindow().stopAction();
  460.     }
  461.     
  462.     /**
  463.      * shutdown the system with specified exit code
  464.      * @param code int
  465.      * @return void
  466.      */
  467.     public void exit( int code )
  468.     {
  469.         System.exit( code );
  470.     }
  471.     
  472.     /**
  473.      * rescue the system
  474.      * @return void
  475.      */
  476.     public void rescue()
  477.     {
  478.         getMainWindow().df.rescue();
  479.     }
  480.     
  481.     /**
  482.      * return the status of system
  483.      * @return boolean
  484.      */
  485.     public boolean ready()
  486.     {
  487.         return getMainWindow().df.ready();
  488.     }
  489.  
  490.  
  491.     /**
  492.      * get the parent object
  493.      * @return MainWindow
  494.      */
  495.     public MainWindow getMainWindow()
  496.     {
  497.         return window;
  498.     }
  499.     
  500.     /**
  501.      * set the parent object
  502.      * @param window MainWindow
  503.      * @return void
  504.      */
  505.     public void setMainWindow( MainWindow window )
  506.     {
  507.         this.window = window;
  508.     }
  509.     
  510.     /**
  511.      * set e_time_to_stop
  512.      * @param time_to_stop double
  513.      * @return void
  514.      */
  515.     public void setTimeToStop( double time_to_stop )
  516.     {
  517.         this.e_time_to_stop = time_to_stop;
  518. //System.out.println( "setTimeToStop (time_to_stop:" + e_time_to_stop + ")" );
  519.     }
  520.  
  521.     /**
  522.      * set the update interval
  523.      * @param update_interval int
  524.      * @return void
  525.      */
  526.     public void setUpdateInterval( int update_interval )
  527.     {
  528.         this.e_update_interval = update_interval;
  529.     }
  530.     
  531.     /**
  532.      * get the update interval
  533.      * @return int
  534.      */
  535.     public int getUpdateInterval()
  536.     {
  537.         return this.e_update_interval;
  538.     }
  539.     
  540.     /**
  541.      * set the step interval
  542.      * @param step_interval double
  543.      * @return void
  544.      */
  545.     public void setStepInterval( double step_interval )
  546.     {
  547.         getMainWindow().df.setDelta( step_interval, 0 );
  548.     }
  549.     
  550.     /**
  551.      * get the step interval
  552.      * @return double
  553.      */
  554.     public double getStepInterval()
  555.     {
  556.         return getMainWindow().df.getDelta();
  557.     }
  558.     
  559.     /**
  560.      * set current time
  561.      * @param current_time double
  562.      * @return void
  563.      */
  564.     public void setCurrentTime( double current_time )
  565.     {
  566.         getMainWindow().df.setTime( current_time );
  567.     }
  568.     
  569.     /**
  570.      * get current time in system
  571.      * @return double
  572.      */
  573.     public double getCurrentTime()
  574.     {
  575.         return getMainWindow().df.getTime();
  576.     }
  577.     
  578.     /**
  579.      * set the script file name
  580.      * @param script_name String
  581.      * @return void
  582.      */
  583.     public void setScriptName( String script_name )
  584.     {
  585.         this.e_script_name = script_name;
  586.     }
  587.     
  588.     /**
  589.      * get the script file name
  590.      * @return String
  591.      */
  592.     public String getScriptName()
  593.     {
  594.         return e_script_name;
  595.     }
  596.     
  597.     /**
  598.      * set the rule file name
  599.      * @param rule_name String
  600.      * @return void
  601.      */
  602.     public void setRuleName( String rule_name )
  603.     {
  604.         this.e_rule_name = rule_name;
  605.     }
  606.     
  607.     /**
  608.      * get the rule file name
  609.      * @return String
  610.      */
  611.     public String getRuleName()
  612.     {
  613.         return e_rule_name;
  614.     }
  615.     
  616.     /**
  617.      * set the cell state file name
  618.      * @param cell_state_name String
  619.      * @return void
  620.      */
  621.     public void setCellStateName( String cell_state_name )
  622.     {
  623.         this.e_cell_state_name = cell_state_name;
  624.     }
  625.     
  626.     /**
  627.      * get the cell state file name
  628.      * @return String
  629.      */
  630.     public String getCellStateName()
  631.     {
  632.         return e_cell_state_name;
  633.     }
  634.  
  635.     /**
  636.      * set running status
  637.      * @param flag boolean
  638.      * @return void
  639.      */
  640.     public void setRunningStatus( boolean flag )
  641.     {
  642.         e_running = flag;
  643.     }
  644.  
  645.     /**
  646.      * get running status
  647.      * @return boolean
  648.      */
  649.     public boolean getRunningStatus()
  650.     {
  651.         return e_running;
  652.     }
  653.  
  654.     /**
  655.      * When a button of MainWindow is pushed, CORE reacts with the corresponding behavior.
  656.      * @param type Window button 0 Start 1 Stop 2 Step
  657.      * @return int
  658.      */
  659.     public int setMainWindowState( int type )
  660.     {
  661.         getMainWindow().messageWindow.setDebugMessage( "-----> setMainWindowState@" + getClass().getName() + "( type:" + type + " )" );
  662.         int ret = 0;
  663.         
  664.         switch( type )
  665.         {
  666.         case 0:        // 
  667.             ret = start();
  668.             break;
  669.         case 1:        // 
  670.             stop();
  671.             setTimeToStop( Double.MAX_VALUE );
  672.             break;
  673.         case 2:        // 
  674.             step();
  675.             break;
  676.         case -1:    // 
  677.             quit();
  678.             break;
  679.         }
  680.         
  681.         getMainWindow().messageWindow.setDebugMessage( "<----- setMainWindowState@" + getClass().getName() + "( ret:" + ret + " )" );
  682.         return ret;
  683.     }
  684.  
  685.     /**
  686.      * Pass Param to CORE when the software starts up. 
  687.      * @param args arg params
  688.      * @return boolean  <code>true</code> rule file was opened
  689.      *                  <code>false</code> rule file wasn't opened
  690.      */
  691.     public boolean setMainWindowsArg( String[] args )
  692.     {
  693.         getMainWindow().messageWindow.setDebugMessage( "-----> setMainWindowsArg@" + getClass().getName() + "( args.length:" + args.length + " )" );
  694.  
  695.         boolean ret = initialize( args );
  696.         
  697.         getMainWindow().messageWindow.setDebugMessage( "<----- setMainWindowsArg@" + getClass().getName() + "( ret:" + ret + " )" );
  698.         return ret;
  699.     }
  700.     
  701.     /**
  702.      * set preferences
  703.      * @param step_interval step interval
  704.      * @param update_interval update interval
  705.      * @return void
  706.      */
  707.     public void setPreference( double step_interval, int update_interval )
  708.     {
  709.         setStepInterval( step_interval );
  710.         setUpdateInterval( update_interval );
  711.     }
  712.     
  713.     /**
  714.      * Get the Preference Step value
  715.      * @return double
  716.      */
  717.     public double getPreferenceStep()
  718.     {
  719.         return getStepInterval();
  720.     }
  721.     
  722.     /**
  723.      * Get the preference update interval value
  724.      * @return int
  725.      */
  726.     public int getPreferenceUpdate()
  727.     {
  728.         return getUpdateInterval();
  729.     }
  730.     
  731.     /**
  732.      * Process Rule file (Load Rule)
  733.      * @param file_path path to rule file
  734.      * @return boolean
  735.      */
  736.     public boolean setRuleFile( String file_path )
  737.     {
  738.         return loadRule( file_path );
  739.         //return ready();
  740.     }
  741.     
  742.     /**
  743.      * Process Script file (Load Script).
  744.      * @param file_path path to script file
  745.      * @return boolean
  746.      */
  747.     public boolean setScriptFile( String file_path )
  748.     {
  749.         getMainWindow().messageWindow.setDebugMessage( "-----> setScriptFile@" + getClass().getName() + "()" );
  750.         loadScript( file_path );
  751.  
  752.         getMainWindow().messageWindow.setDebugMessage( "<----- setScriptFile@" + getClass().getName() + "()" );
  753.         return ready();
  754.     }
  755.     
  756.     /**
  757.      * Process CellState file (Load Cell State)
  758.      * @param file_path path to cell state file
  759.      * @return void
  760.      */
  761.     public void setCellStateFile( String file_path )
  762.     {
  763.         loadCellState( file_path );
  764.     }
  765.     
  766.     /**
  767.      * Process CellState file (Save Cell State). 
  768.      * @param file_path path to cell state file
  769.      * @return void
  770.      */
  771.     public void saveCellStateFile( String file_path )
  772.     {
  773.         saveCellState( file_path );
  774.     }
  775.     
  776.     
  777.     public void setScriptRunning( boolean status )
  778.     {
  779.         bScriptRunning = status;
  780. //System.out.println( "-----> setScriptRunning@" + getClass().getName() + "(bScriptRunning:" + bScriptRunning + ")" );
  781.     }
  782.     
  783.     public boolean getScriptRunning()
  784.     {
  785.         return bScriptRunning;
  786.     }
  787.     
  788.  
  789.     public void stopScript()
  790.     {
  791.         setScriptRunning( false );
  792.         script = null;
  793.         // 2002.5
  794.         //getMainWindow().setScriptFileName( "" );
  795.     }
  796.  
  797.     
  798.     /**
  799.      * analyze the program boot parameters
  800.      * @param args String[]
  801.      * @return boolean
  802.      */
  803.     private boolean initialize( String[] args )
  804.     {
  805.         getMainWindow().messageWindow.setDebugMessage( "-----> initialize@" + getClass().getName() + "( args.length:" + args.length + " )" );
  806.         
  807.         System.out.println( Engine.msg_welcome );
  808. //        if (the_engine == NULL) {
  809. //            the_engine = new engine_c();
  810. //        }
  811.  
  812.         Properties pp = getArgList( args );
  813.  
  814.         for( Enumeration enum = pp.propertyNames(); enum.hasMoreElements(); )
  815.         {
  816.             String key = (String)enum.nextElement();
  817.             
  818.             if( key.equals( "a" ) ||
  819.                 key.equals( "c" ) ||
  820.                 key.equals( "d" ) ||
  821.                 key.equals( "r" ) ||
  822.                 key.equals( "t" ) ||
  823.                 key.equals( "u" ) )
  824.             {
  825.                 continue;
  826.             }
  827.             else if( key.equals( "f" ) )
  828.             {
  829.                 this.getMainWindow().messageWindow.setDebugMessage( "script file name:" + pp.getProperty( key ) );
  830.                 setScriptName( pp.getProperty( key ) );
  831.             }
  832.             else if( key.equals( "D" ) )
  833.             {
  834.                 getMainWindow().messageWindow.setDebugFlag( true );
  835.                 this.e_debug = true;
  836.             }
  837.             else
  838.             {
  839.                 System.out.println( Engine.msg_help );
  840.                 exit( 1 );
  841.             }
  842.         }
  843.  
  844.         getMainWindow().df.initCore( args.length, mergeStringArgs( args ) );
  845.         startup();
  846.  
  847.         getMainWindow().messageWindow.setDebugMessage( "<----- initialize@" + getClass().getName() + "()" );
  848.         return ready();
  849.     }
  850.     
  851.     /**
  852.      * analyze startup args and set into Properties
  853.      * @param args String[]
  854.      * @return Properties
  855.      */
  856.     private Properties getArgList( String[] args )
  857.     {
  858.         Properties pp = new Properties();
  859.         String key = null;
  860.         String value = "";
  861.         for( int i = 0; i < args.length; i++ )
  862.         {
  863.             if( args[i].trim().startsWith( "-" ) )
  864.             {
  865.                 key = args[i].substring( args[i].indexOf( '-' ) + 1 );
  866.             }
  867.             else
  868.             {
  869.                 value = args[i];
  870.             }
  871.             if( key != null )
  872.             {
  873.                 pp.setProperty( key, value );
  874.                 value = "";
  875.             }
  876.         }
  877.         
  878.         return pp;
  879.     }
  880.     
  881.     private String mergeStringArgs( String[] args )
  882.     {
  883.         StringBuffer buf = new StringBuffer();
  884.         
  885.         for( int i = 0; i < args.length; i++ )
  886.         {
  887.             buf.append( args[i] );
  888.             buf.append( "\n" );
  889.         }
  890.         
  891.         return buf.toString();
  892.     }
  893.     
  894.     public void debugFunc( String str )
  895.     {
  896. /**
  897.         if( e_debug )
  898.         {
  899.             System.out.println( "JAVA::" +str );
  900.         }
  901. **/
  902.         getMainWindow().messageWindow.setDebugMessage( str );
  903.     }
  904.     
  905.     
  906.     public Object[] getMsgWelcome()
  907.     {
  908.         Object[] obj = new Object[3];
  909.         try
  910.         {
  911.         // 2002.1.24 create welcome message string
  912.         StringBuffer buf = new StringBuffer();
  913.         buf.append( "E-CELL 2 (C) 1998-2002 Keio university and JST\n" );
  914.         buf.append( "Version " );
  915.         buf.append( window.df.getCoreVersion() );
  916.         buf.append( "\n" );
  917.         buf.append( "This is free software without any warranty under GPL.\n" );
  918.         buf.append( "Please see " );
  919.         
  920.             java.net.URL url = new java.net.URL( "http://bioinformatics.org/project/?group_id=49" );
  921.         
  922.         String str = "for detail.\n";
  923.         
  924.         obj[0] = buf.toString();
  925.         obj[1] = url;
  926.         obj[2] = str;
  927.         }
  928.         catch( Exception e )
  929.         {
  930.             getMainWindow().messageWindow.setErrorMessage( e );
  931.         }
  932.         
  933.         return obj;
  934.     }
  935. }
  936.  
  937.